const http = require('http')
const app = http.createServer()
const fs = require('fs')

app.on('request',(req,res) => {
  fs.readFile(__dirname + '/index.html', (err, data) => {
    if (err) {
      res.writeHead(500)
      return res.end('error loading index.html')
    }
    res.writeHead(200)
    res.end(data)
  })
})

app.listen(3000,() => {
  console.log('服务器启动成功');
})

const io = require('socket.io')(app)

io.on('connection', function (socket) {
  console.log('一个客户端连接了');
  socket.emit('send', {name: 'zoe'})
})
